11. Filtering and RANSAC

Filtering and RANSAC

Now it's time to add the steps you used in the last lesson to isolate the objects on top of the table. But this time around, before you can operate on the point cloud using python-pcl you'll need to convert it from a ROS message (which is in PointCloud2 message format) into PCL format. There's a handy function to do this provided for you in pcl_helper.py. Investigate the contents of pcl_helper.py and discover the function you need!

This function takes in a ROS message of type PointCloud2 and converts it to PCL PointXYZRGB format. Add it to the pcl_callback() function in your node under the following TODO:

# TODO: Convert ROS msg to PCL data

Now you're ready to apply filters and perform RANSAC plane segmentation! As a reminder, here are the steps you need to take:

  1. Downsample your point cloud by applying a Voxel Grid Filter.
  2. Apply a Pass Through Filter to isolate the table and objects.
  3. Perform RANSAC plane fitting to identify the table.
  4. Use the ExtractIndices Filter to create new point clouds containing the table and objects separately (I'll call them cloud_table and cloud_objects going forward).

Once you've done that, you can convert these new clouds back to ROS message format and publish them to the topics you created earlier called /pcl_objects and /pcl_table. To do the conversion to message format you'll use another helper function from pcl_helper.py. Head back over and investigate pcl_helper.py to figure out which function to use!

To apply this function to your point clouds, add it to your pcl_callback() function in your node under the following TODO:

# TODO: Convert PCL data to ROS msg
ros_cloud_objects =  
ros_cloud_table = 

Then publish these new ROS messages instead of the dummy data you were publishing previously:

# TODO: Publish ROS msg
pcl_objects_pub.publish(ros_cloud_objects)
pcl_table_pub.publish(ros_cloud_table)

Save and run your node (mine's called segmentation.py):

$ cd ~/catkin_ws/src/sensor_stick/scripts/
$ ./segmentation.py

Now, if your filtering and RANSAC operations functioned properly, in RViz you should see only the table when you select the /pcl_table topic and only the objects when you select the /pcl_objects topic like this: